<?php

namespace src\baseModels;

use Yii;

/**
 * This is the model class for table "{{%meetings}}".
 *
 * @property integer $id
 * @property integer $user_id
 * @property string $email_tpl
 * @property string $phone_tpl
 * @property string $title
 * @property string $describe
 * @property string $location
 * @property string $location_name
 * @property string $method
 * @property integer $started_at
 * @property integer $end_at
 * @property integer $created_at
 * @property integer $updated_at
 * @property integer $status
 *
 * @property Information[] $informations
 * @property User $user
 * @property Members[] $members
 */
class Meetings extends \common\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{meetings}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'title', 'describe', 'location', 'location_name', 'method', 'started_at', 'end_at'], 'required'],
            [['user_id', 'started_at', 'end_at', 'created_at', 'updated_at'], 'integer'],
            [['email_tpl', 'phone_tpl'], 'string'],
            [['title'], 'string', 'max' => 255],
            [['describe', 'location', 'location_name', 'method'], 'string', 'max' => 500]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => '用户ID',
            'email_tpl' => 'EMAIL模板',
            'phone_tpl' => '短信模板',
            'title' => '会议主题',
            'describe' => '会议简介',
            'location' => '会议经纬度',
            'location_name' => '会议地点',
            'method' => '签到验证方式',
            'started_at' => '开始时间',
            'end_at' => '结束时间',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getInformations()
    {
        return $this->hasMany(Information::className(), ['meeting_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), ['id' => 'user_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getMembers()
    {
        return Members::findByMeetingId($this->id);
    }
}
